package cn.itcast.bos.service.take_delivery.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.take_delivery.PromotionDao;
import cn.itcast.bos.domain.take_delivery.PageBean;
import cn.itcast.bos.domain.take_delivery.Promotion;
import cn.itcast.bos.service.take_delivery.PromotionService;

@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {

	@Autowired
	private PromotionDao promotionDao;
	
	@Override
	public void save(Promotion model) {
		promotionDao.save(model);
		
	}

	@Override
	public Page<Promotion> queryPage(Pageable pageable) {
		
		return promotionDao.findAll(pageable);
	}

	@Override
	public PageBean<Promotion> queryPromotion(Integer page, Integer rows) {
		Pageable pageable = new PageRequest(page-1, rows);
		Page<Promotion> page2 = promotionDao.findAll(pageable);
		PageBean<Promotion> pageBean = new PageBean<Promotion>();
		pageBean.setTotalCount(page2.getTotalElements());
		pageBean.setPageData(page2.getContent());
		return pageBean;
	}

	@Override
	public Promotion queryPromotionById(Integer id) {
		
		return promotionDao.findOne(id);
	}

	@Override
	public void update() {
		promotionDao.update();
	}
	
	
}
